////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __WN_DATA_TYPE_H__
#define __WN_DATA_TYPE_H__

// This is included because of a bug in VS2008 (It generated the wrong vtable size for WNScriptingEngine)
// IT does not need to be included otherwise

#include "WNCore/inc/WNBase.h"

#if defined _WN_WINDOWS && _WN_MSVC < 160000000
    #include "WNScripting/inc/WNScriptingEnginePublic.h"
#endif

#include "WNScripting/inc/WNParseNode.h"
#include "WNScripting/inc/WNTypeManager.h"
#include "WNScripting/inc/WNIdentifierMap.h"

class WNExpression;

class WNDataType : public WNParseNode {
public:
    WNDataType(WN_SIZE_T _startLine,
               WN_SIZE_T _endLine,
               WN_SIZE_T _startChar,
               WN_SIZE_T _endChar,
               WNVariableType _type);

    WNDataType(WN_SIZE_T _startLine, 
               WN_SIZE_T _endLine,
               WN_SIZE_T _startChar,
               WN_SIZE_T _endChar, 
               WNIdentifierElement _name);

    WNDataType(WN_SIZE_T _startLine,
               WN_SIZE_T _endLine,
               WN_SIZE_T _startChar,
               WN_SIZE_T _endChar,
               WNDataType* _subType);

    WNDataType(WN_SIZE_T _startLine,
               WN_SIZE_T _endLine,
               WN_SIZE_T _startChar,
               WN_SIZE_T _endChar,
               WNDataType* _subType,
               WNExpression* _arraySize);

    virtual llvm::Value* OptimizeAndGenerate(WNScriptingEngineData& _scriptingData, WNFunctionDecl* _functionDecl);
    virtual llvm::Value* OptimizeAndGenerateArray(WNScriptingEngineData& _scriptingData, WNFunctionDecl* _functionDecl, std::list<WNDataType*>& _optimizationList);

    WNTypeElement GetType();
    WNDataType* GetSubType();
    llvm::Value* GetOptimizedLength();
    WNIdentifierElement GetName();
    const std::list<WNDataType*>* GetSubTypeArray();

private:
    WNVariableType mType;
    WNIdentifierElement mName;
    WNTypeElement mElementType;
    WNDataType*   mSubType;
    WNExpression* mLength;
    llvm::Value* mLengthVal;
    std::list<WNDataType*> mOptimizationList;
};

#endif // __WN_DATA_TYPE_H__